#pragma once

#include <vector>
#include <map>

#include <maya/MQuaternion.h>

struct TMayaExportTriangle
{
	int vertex_idx[3];
	int normal_idx[3];
	int tangent_idx[3];
	int uv_idx[3];
};

struct TMayaBaseMesh
{
	MString Name;
	
	MPointArray Vertices;
	std::vector<TMayaExportTriangle> Triangles;
};

struct TMayaExportMesh: TMayaBaseMesh
{
	MFloatVectorArray Normals;
	MFloatVectorArray Tangents;
	MFloatArray U_Coords;
	MFloatArray V_Coords;
};

struct TMayaExportWeight
{
	int Influences[3];
	float Values[3];

	TMayaExportWeight()
	{
		memset(Influences, 0, 3 * sizeof(Influences[0]));
		memset(Values, 0, 3 * sizeof(Values[0]));
	}
};

struct TMayaExportSkinnedTriangle: TMayaExportTriangle
{
	int weight_idx[3];
	int influence_idx[3];
};

struct TMayaExportSkinnedMesh: TMayaExportMesh
{
	MFloatVectorArray Weights;
	MIntArray Influences;
};

struct TMayaExportJoint
{
	//MMatrix Transform;
	
	MFloatVector Position;
	MQuaternion Rotation;
	int Parent;

	MString Name;
};

struct TMayaExportSkin
{
	MString Name;
	MString MeshName;
	
	typedef std::vector<TMayaExportJoint> TAnimFrame;
	std::vector<TAnimFrame> Joints;
	
	//TMayaExportSkinnedMesh Mesh;
	
	std::vector<TMayaExportWeight> Weights;

	enum { MAX_INFLUENCES = 3 };
};

struct TMayaExportLocator
{
	MFloatVector Position;
	MString Name;
};

class TBaseMayaExportTarget abstract
{
public:
	virtual MStatus GetOutputPath(MString& target) {return MS::kSuccess;};
	virtual MStatus SaveFile(MString filename) {return MS::kSuccess;};

	virtual void AddMesh(TMayaExportMesh& mesh) {};
	virtual void AddCollisionMesh(TMayaBaseMesh& mesh) {};
	virtual void AddSkin(TMayaExportSkin& skin) {};
	virtual void AddLocator(TMayaExportLocator& locator) {};
};

